package com.liang.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.liang.pojo.Excuse;
import com.liang.empty.Result;
import com.liang.pojo.dto.ExcuseDto;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;;
import java.util.List;
import com.liang.service.ExcuseService;

import javax.annotation.Resource;

/**
 *@作者:lsk
 *Controller接口
 *@Date:2023/10/22
*/
@RestController
@RequestMapping("/ExcuseURL")
public class ExcuseController {


	@Autowired
	private ExcuseService excuseservice;


	/**
	根据Excuse_id查询
	*/
	@GetMapping("/selectByExcuse_id/{excuse_id}")
	public Result selectByExcuse_id(@PathVariable(value = "excuse_id") Long excuse_id){
		return Result.buildMessage(excuseservice.selectByExcuse_id(excuse_id),"查询成功",200);
	}


	/**
	根据Excuse_id更新
	*/
	@PostMapping("/updateByExcuse_id")
	public Result updateByExcuse_id(@RequestBody Excuse demo){
		return Result.buildMessage(excuseservice.updateByExcuse_id( demo),"修改成功",0);
	}



	/**
	根据Excuse_id删除
	*/
	@GetMapping("/deleteByExcuse_id/{excuse_id}")
	public Result deleteByExcuse_id(@PathVariable(value = "excuse_id") Long excuse_id){
		return Result.buildMessage(excuseservice.deleteByExcuse_id(excuse_id),"删除成功",0);
	}





	/**
	 insert:(插入)
	*/
	@PostMapping("/insert")
	public Result insert(@RequestBody Excuse demo){
		Result.buildSuccess(excuseservice.insert(demo));
		return Result.buildMessage(demo,"添加成功",0);
	}



	/**
	 insertOrUpdate(插入或更新(根据主键或唯一索引更新，主键和唯一索引不会改变))
	*/
	@PostMapping("/insertOrUpdate")
	public Result insertOrUpdate(@RequestBody Excuse demo){
		return Result.buildMessage(excuseservice.insertOrUpdate(demo),"插入或更新成功",200);
	}



	/**
	 insertBath:(批量插入)
	*/
	@PostMapping("/insertBatch")
	public Result insertBatch(@RequestBody List<Excuse> list){
		return Result.buildMessage(excuseservice.insertBatch(list),"批量插入成功",200);
	}



	/**
	 insertOrUpdateBatch:(批量插入或更新)
	*/
	@PostMapping("/insertOrUpdateBatch")
	public Result insertOrUpdateBatch(@RequestBody List<Excuse> list){
		return Result.buildMessage(excuseservice.insertOrUpdateBatch(list),"批量更新成功",200);
	}



	/**
	 selectList:(根据参数查询集合)
	*/
	@PostMapping("/selectList")
	public Result selectList(@RequestBody Map<String,Object> param){
		Map map = new HashMap<String,Object>();
		if(param.get("pageNum") != null){
			map.put("total",excuseservice.selectCount(param));
		}
		map.put("data",excuseservice.selectList(param));
		return Result.buildMessage(map,"查询成功",200);
	}



	/**
	 selectCount:(根据集合查询数量)
	*/
	@PostMapping("/selectCount")
	public Result selectCount(@RequestBody Map<String,Object> param){
		return Result.buildMessage(excuseservice.selectCount(param),"查询数量成功",200);
	}

	/**
	 * 用于增加假条，需要前端传过来userid，请假开始时间，请假结束时间，请假的理由
	 */
	@PostMapping("/addExcuse")
	public  Result addExcuse(@RequestBody Excuse excuse){

		Boolean bit = excuseservice.addExcuse(excuse);
		if(bit) return Result.buildSuccess();
		else return Result.buildFail(1,"服务器繁忙!!!");

	}


	/**
	 * 上级审批下级请假条
	 * @param excuseDto
	 * @return
	 */
	@PostMapping("/approveExcuse")
	public Result approveExcuse(@RequestBody ExcuseDto excuseDto){

		Boolean  bit = excuseservice.approveExcuse(excuseDto);
		if(bit) return Result.buildSuccess();
		else return Result.buildFail(1,"服务器繁忙!!!");
}

	/**
	 * 用户销假
	 * @param excuseid
	 * @return
	 */
	@GetMapping("/deleteExcuse/{excuseid}")
	public  Result deleteExcuse(@PathVariable("excuseid") Long excuseid){

	 Boolean bit =	excuseservice.deleteExcuse(excuseid);
	 if(bit) return  Result.buildSuccess();
	 else return  Result.buildFail(1,"服务器繁忙!!!");
	}

	/**
	 * 获取用户申请的请假条列表，条件查询,由前端分页进行 ,result中的date为一个map对象。包括总记录数目，和请假条列表。
	 * @return
	 */
	@PostMapping("/approveExcuseList")
	public Result approveExcuseList(@RequestBody ExcuseDto excuseDto){

	Map map  = 	excuseservice.approveExcuseList(excuseDto);

	return Result.buildSuccess(map);
	}

	/**
	 * 获取当前用户正在申请的请假记录
	 * @param userid
	 * @return
	 */
	@GetMapping("/approvingExcuseList/{userid}")
	public Result approvingExcuseList(@PathVariable("userid") Long userid){
		Map map = excuseservice.approvingExcuseList(userid);
		return  Result.buildSuccess(map);
	}

	/**
	 * 获取当前用户的请假条的历史记录，分页+条件查询
	 * @param excuseDto
	 * @return
	 */
	@PostMapping("/approvedExcuseList")
	public  Result approvedExcuseList(@RequestBody ExcuseDto excuseDto){

	 Map map = excuseservice.approvedExcuseList(excuseDto);

		return  Result.buildSuccess(map);
	}

	/**
	 * 获取本单位请求销假的列表信息
	 */
	@PostMapping("/deletingExcuseList")
	public  Result deletingExcuseList(@RequestBody ExcuseDto excuseDto){

	Map map = excuseservice.getDeletingExcuseList(excuseDto);
		return Result.buildSuccess(map);
	}

	/**
	 * 上级批阅对本单位的销假申请操作。
	 * @param excuseDto
	 * @return
	 */
	@PostMapping("/superiorDeleteExcuse")
	public  Result superiorDeleteExcuse(@RequestBody ExcuseDto excuseDto){

	 Boolean state = excuseservice.superiorDeleteExcuse(excuseDto);

	 if(state) return  Result.buildSuccess();
	 else return  Result.buildFail(1,"服务器繁忙!");
	}


	/**
	 * 用户正在进行的假期列表，未销假
	 * @param excuseDto
	 * @return
	 */
	@PostMapping("/willDeleteExcuse")
	public Result willDeleteExcuse(@RequestBody ExcuseDto excuseDto){

	  Map map =	excuseservice.willDeleteExcuse(excuseDto);
	  return Result.buildSuccess(map);
	}
}